﻿using System.Collections.Generic;
using ECG.Common;
using ECG.DAL.Infrastructure;
using ECG.Utility;

namespace ECG.DAL
{
    public partial class BannerDb
    {
        /// <summary>
        /// Lấy về tất cả Banner đang được đăng
        /// </summary>
        /// <returns></returns>
        public static List<ViewBannerClientDto> GetAllBanner()
        {
            var bannerList = CacheLayer.Get<List<ViewBannerClientDto>>(ConstVariable.MemCahceBanner);
            if(bannerList == null)
            {
                var dao = SharedSqlDao;
                var command = dao.GetDbSprocCommand("WSPX_Banner_GetAll");
                try
                {
                    bannerList = dao.GetDTOList<ViewBannerClientDto>(ref command);
                    if(bannerList != null)
                    {
                        CacheLayer.Add(bannerList, ConstVariable.MemCahceBanner);
                    }
                }
                finally
                {
                    command.Connection.Close();
                }
            }
            return bannerList;
        }
    }
}
